/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg1142012_buoi01;

/**
 *
 * @author HONGDIEM
 */
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void LuaChon(){
        System.out.println("--------------------------------");
        System.out.println("- 1.Phep toan +                -");
        System.out.println("- 2.Phep toan -                -");
        System.out.println("- 3.Phep toan x                -");
        System.out.println("- 4.Phep toan /                -");
        System.out.println("- 5.Phep toan %                -");
        System.out.println("- 6.Thoat                      -");
        System.out.println("- 7.Ban chon 1-6               -");
        
    }
    public static void ThucDon(){
        System.out.println("------------------------------");
        System.out.println("- 1.Bai Tap 1                -");
        System.out.println("- 2.Bai Tap 2                -");
        System.out.println("- 3.Bai Tap 3                -");
        System.out.println("- 4.Bai Tap 4                -");
        System.out.println("- 5.Bai Tap 5                -");
        System.out.println("- 6.Bai Tap 6                -");
        System.out.println("- 7.Bai Tap 7                -");
        System.out.println("- 8.Bai Tap 8                -");
        System.out.println("- 9.Bai Tap 9                -");
        System.out.println("- 10.Bai Tap 10              -");
        System.out.println("- 11.Bai Tap 11              -");
        System.out.println("- 12.Bai Tap 12              -");
        System.out.println("- 13.Bai Tap 13              -");
        System.out.println("- 14.Bai Tap 14              -");
        System.out.println("- 15.Bai Tap 15              -");
        System.out.println("- 16.Bai Tap 16              -");
        System.out.println("- 17.Bai Tap 17              -");
        System.out.println("- 18.Bai Tap 18              -");
        System.out.println("- 19.Bai Tap 19              -");
        System.out.println("- 20.Bai Tap 20              -");
        System.out.println("- 21.Bai Tap 21              -");
        System.out.println("- 22.Bai Tap 22              -");
        System.out.println("- 23.Bai Tap 23              -");
        System.out.println("- 24.Bai Tap 24              -");
        System.out.println("- 25.Bai Tap 25              -");
        System.out.println("- 26.Bai Tap 26              -");
        System.out.println("- 27.Bai Tap 27              -");
        System.out.println("- 28.Bai Tap 28              -");
        System.out.println("- 29.Bai Tap 29              -");
        System.out.println("- 30.Bai Tap 30              -");
        System.out.println("- 31.Bai Tap 31              -");
        System.out.println("- 32.Bai Tap 32              -");
        System.out.println("- 33.Bai Tap 33              -");
        System.out.println("- 34.Bai Tap 34              -");
        System.out.println("- 35.Bai Tap 35              -");
        System.out.println("- 36.Bai Tap 36              -");
        
        System.out.println("------------------------------");
        System.out.println("-37.Thoat---------------------");
        System.out.println(" Ban chon (1-37):");
    }
    public static void BaiTap01(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 3 || n>= 50);
        int s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s = s + i ;
        }
        System.out.println("s = " + s);
    }
    public static void BaiTap02(){
         int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n < 5 || n > 20);
         int s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s = s + i * i ;
        }
        System.out.println("s = " + s);
    }
    public static void BaiTap03(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n < 7);
        float s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s = s +( float) 1 / i ;
        }
        System.out.println("s = " + s);
    }
      public static void BaiTap04(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 9);
        float s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s =  s + (float)1 /( 2 * i)  ;
        }
        System.out.println("s = " + s);
    }
       public static void BaiTap05(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n < 2);
        float s = 1;
        for ( int i = 1 ; i <= n ; i ++){
            s =  s + (float)1 /( 2 * i + 1)  ;
        }
        System.out.println("s = " + s);
    }
        public static void BaiTap06(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 6);
        float s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s =  s + (float)1 /( 2 * ( i + 1))  ;
        }
        System.out.println("s = " + s);
    }
        public static void BaiTap07(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n < 1);
        float s = 0;
        for ( int i = 1 ; i <= n ; i ++){
            s =  s + (float) i / (i + 1)  ;
        }
        System.out.println("s = " + s);
    }
         public static void BaiTap08(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 5);
        float s = 0;
        int i = 1;
        while ( i <= 2 * n + 1)
        {
            s = s + (float) i / ( i + 1);
            i = i + 2;
        
        }
        System.out.println("s = " + s);
    }
         public static void BaiTap09(){
        int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 6);
        int  t = 1;
        int i = 1;
        while ( i <= n)
        {
            t = t * i;
            i = i + 1;
        }
        System.out.println("t = " + t);
    }
          public static void BaiTap10(){
        int n ;
        int x ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        System.out.print("x=");
        x = Integer.parseInt(scan.nextLine());
        int t = 1;
        int i = 1;
        while ( i <= n)
        {
            t = t * x;
            i = i + 1;
        }
        System.out.println("t = " + t);
    }
            public static void BaiTap11(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int t = 1;
        int s = 0;
        int i = 1;
        while ( i <= n)
        {
            t = t * i;
            s = s + t;
            i = i + 1;
        }
        System.out.println("t = " + s);
    }
             public static void BaiTap12(){
        int n ;
        int x ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        System.out.print("x=");
        x = Integer.parseInt(scan.nextLine());
        float t = 1;
        float s = 0;
        int i = 1;
        while ( i <= n)
        {
            t = t * x;
            s = s + t;
            i = i + 1;
        }
        System.out.println("s = " + s);
    }
               public static void BaiTap13(){
        int n ;
        int x ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        System.out.print("x=");
        x = Integer.parseInt(scan.nextLine());
        float t = 1;
        float s = 0;
        int i = 2;
        while ( i <= 2 * n)
        {
            t = t * x * x;
            s = s + t;
            i = i + 2;
        }
        System.out.println("s = " + s);
    }
                  public static void BaiTap14(){
        int n ;
        int x ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        System.out.print("x=");
        x = Integer.parseInt(scan.nextLine());
        float t = x;
        float s = x;
        int i = 3;
        while ( i <= 2 * n + 1)
        {
            t = t * x * x;
            s = s + t;
            i = i + 2;
        }
        System.out.println("s = " + s);
    }
        public static void BaiTap15(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int t = 1;
        int i = 2;
        while ( i <= n)
        {
            t =  t *  i ;
            i = i + 1;
        }
        System.out.println("t = " + t);
    }
     public static void BaiTap16(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int i = 1;
        while ( i <= n)
        {
            if( n % i == 0)
                 System.out.println("uoc so cua n la: " + i);
            i = i + 1;
        }
     }
      public static void BaiTap17(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int i = 1;
        int s = 0;
        int t = 1;
        while ( i <= n)
        {
            if( n % i == 0)
            {
                 s = s + i;
                 t = t * i;
            }
            i = i + 1;
        }
        System.out.println("tong cac uoc so cua n la: " + s );
        System.out.println("tich cac uoc so cua n la: " + t );
     }
      public static void BaiTap18(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int i = 1;
        int dem = 0;
        int demchan = 0;
        int demle = 0;
        while ( i <= n)
        {
            if( n % i == 0){
                 dem = dem + 1;
                 if ( i % 2 == 0)
                    demchan = demchan + 1;
                 else
                     demle = demle + 1;
            }
            i = i + 1;
        }
         System.out.println("so luong uoc so cua n: " + dem );
         System.out.println("so luong uoc so chan cua n: " + demchan );
         System.out.println("so luong uoc so le cua n: " + demle );
     }
       public static void BaiTap19(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int i = 1;
        int dem = 0;
        while ( i <= n)
        {
            if( n % i == 0)
                dem = dem + 1;
            i = i + 1;
        }
        if (dem == 2)
            System.out.println("so vua nhap la so nguyen to" );
        if (dem != 2)
            System.out.println("so vua nhap khong la so nguyen to" );
     }
        public static void BaiTap20(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int i = 0;
        int flag = 0;
        while ( i <= n)
        {
            if(i * i == n)
                flag = 1;
            i = i + 1;
        }
        if (flag == 1)
            System.out.println("so vua nhap la so chinh phuong" );
        else
            System.out.println("so vua nhap khong la so chinh phuong" );
     }
         public static void BaiTap21(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int m;
        System.out.print(" m =");
        m = Integer.parseInt(scan.nextLine());
        int a = Math.abs(n);
        int b = Math.abs(m);
        while ( a * b != 0)
        {
            if( a > b)
                a = a - b;
            b = b - a;
        }
        System.out.println("uoc chung lon nhat cua 2 so vua nhap la: " +(a + b));
    }
          public static void BaiTap22(){
        int n ;
        Scanner scan = new Scanner(System.in);
        System.out.print("n=");
        n = Integer.parseInt(scan.nextLine());
        int m;
        System.out.print(" m =");
        m = Integer.parseInt(scan.nextLine());
        int a = Math.abs(n);
        int b = Math.abs(m);
        while ( a * b != 0)
        {
            if( a > b)
                a = a - b;
            b = b - a;
        }
        int bc = (m * n)/(a + b);
        System.out.println("boi chung nho nhat cua 2 so vua nhap la: " + bc);
    }
           public static void BaiTap23(){
        int a ;
        Scanner scan = new Scanner(System.in);
        System.out.print("a=");
        a = Integer.parseInt(scan.nextLine());
        int b;
        System.out.print("b =");
        b = Integer.parseInt(scan.nextLine());
        while ( a == b)
        {
            if( b == 0)
                System.out.println("phuong trinh da cho co vo so nghiem");
            System.out.println("phuong trinh da cho vo nghiem");
        }
        float x = -b / a;
        System.out.println("nghiem cua phuong trinh la: " + x);
    }
           public static void BaiTap24(){
        int a ;
        Scanner scan = new Scanner(System.in);
        System.out.print("a=");
        a = Integer.parseInt(scan.nextLine());
        int b;
        System.out.print("b =");
        b = Integer.parseInt(scan.nextLine());
        int c;
        System.out.print("c =");
        c = Integer.parseInt(scan.nextLine());
        int delta = b * b - 4 * a * c;
        while ( delta <= 0)
        {
            if( delta == 0)
            {
                float x = -b / (2 * a);
                System.out.println("nghiem cua phuong trinh la :" + x);
            }
            System.out.println("phuong trinh da cho vo nghiem");
        }
        float  x1 = (float)(-b + Math.sqrt(delta))/( 2 * a);
        float  x2 = (float)(-b - Math.sqrt(delta))/( 2 * a);
        System.out.println("nghiem thu 1 cua phuong trinh la: " + x1);
        System.out.println("nghiem thu 2 cua phuong trinh la: " + x2);
    }
           public static void BaiTap25(){
        int nam ;
        Scanner scan = new Scanner(System.in);
        System.out.print("nam=");
        nam = Integer.parseInt(scan.nextLine());
        if(nam % 4 != 0)
            System.out.println("nam vua nhap khong phai la nam nhuan");
        else
            if(nam % 400 == 0)
                System.out.println("nam vua nhap la nam nhuan");
                else
                    if(nam % 100 == 0)
                        System.out.println("nam vua nhap khong phai la nam nhuan");
                        else
                            System.out.println("nam vua nhap la nam nhuan");
    }
           public static void BaiTap26(){
         int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 0);
        for(int i = 0 ; i < n ; i++ )
            if ( i % 2 !=0)
                System.out.println("so nguyen le nho hon so n la:" + i);
    } 
            public static void BaiTap27(){
         int n ;
        Scanner scan = new Scanner(System.in);
        do{
            System.out.print("n=");
            n = Integer.parseInt(scan.nextLine());
        }while ( n <= 0);
        for(int i = 0 ; i < n ; i++ )
            if ( i % 2 !=0 && i !=7 && i !=21 && i!= 41)
                System.out.println("so nguyen le nho hon so n la:" + i);
    } 
         
         
          
           
           public static  void BaiTap28(){
                int h;
               Scanner scan = new Scanner(System.in);
               do {
               System.out.print(" h = ");
               h = Integer.parseInt(scan.nextLine());
               }while( h <= 0);
               int i;
               int j;
             
                        
               for( i = 1 ; i <= h ; i ++)
               {
                   for ( j = 1 ; j <= h - i ; j++)
                       
                       System.out.print("  ");
                       for (int k = 1 ; k <= i  ; k++)
                       {
                           System.out.print(" *  ");
                       } 
                                 
                       System.out.println();
                   
                   
               }
          
           }
            public static  void BaiTap29(){
               int h;
               Scanner scan = new Scanner(System.in);
               System.out.print(" h = ");
               h = Integer.parseInt(scan.nextLine());
               /*int i;
               int j;
               for ( i  = 0 ; i < h ; i++)
               {
                   for ( j = 0 ; j <2 * h - i ; j++)
                   {
                       if (( h - i == j)||(j == h + i)||((i == h - 1 ))&&(h - i <= j))
                           //&&(h - i <= j)
                           System.out.print("*   ");
                       else
                           System.out.print("  ");
                   }
                   System.out.println();
                   
               }
               System.out.println("\n");*/
               for(int i=0; i<h-1; i++){
                   
                    for(int j=0; j<2*h-1; j++){
                        if(i+j==h-1||j-i==h-1){
                            System.out.print("*");
                        }
                        else{
                            System.out.print(" ");
                        }
                    }
                    System.out.println();
                }
               for(int i=0; i<h; i++){
                   System.out.print("* ");
               }
               System.out.println();
          }
       public static  void BaiTap30(){
               int h;
               Scanner scan = new Scanner(System.in);
               System.out.print(" h = ");
               h = Integer.parseInt(scan.nextLine());
               int i;
               int j;
               for( i = 1 ; i <= h ; i ++)
               {
                   for ( j = 0 ; j <= h - 1  ; j++)
                       System.out.print("  ");
                       for (int k = 1 ; k <= i ; k++)
                       {
                           System.out.print("* ");
                       } 
                                   
                        System.out.println();
               }
           }
       public static  void BaiTap32(){
               int m;
               int n;
               Scanner scan = new Scanner(System.in);
               System.out.print(" so dong (chieu rong): ");
               m = Integer.parseInt(scan.nextLine());
               System.out.print(" so cot (chieu dai) : ");
               n = Integer.parseInt(scan.nextLine());
               int i;
               int j;
                for( i = 1 ; i <= m; i ++)
               {
                   for ( j = 1 ; j <= m - i ; j++)
                       System.out.print("* ");
                       for (int k = 1 ; k <= n + i - m ; k++)
                       {
                           System.out.print("* ");
                       } 
                                   
                        System.out.println(" \n ");
               }
                       
              
           }
        public static  void BaiTap31(){
               int h;
               Scanner scan = new Scanner(System.in);
               System.out.print(" chieu cao : ");
               h = Integer.parseInt(scan.nextLine());
               int i;
               int j;
               for(i = 0 ; i < h ; i++)
               {
                   for(j = 0 ; j <h ; j++)
                   {
                       if (j == 0 || i == h - 1 || i == j )
                           System.out.print("* ");
                       else
                           System.out.print("  ");
                   }
                    System.out.println();
                                   
                      
               }
                       
              
           }
        public static  void BaiTap33(){
               int rong;
               int dai;
               Scanner scan = new Scanner(System.in);
               System.out.print(" so dong (chieu rong): ");
               rong = Integer.parseInt(scan.nextLine());
               System.out.print(" so cot (chieu dai) : ");
               dai = Integer.parseInt(scan.nextLine());
               int i;
               int j;
                for( i = 0 ; i < rong ; i++)
                {
                    for(j = 0 ; j < dai ; j++ )
                        if (i == 0 || j == 0 || i == (rong- 1)|| j == (dai- 1))
                            System.out.print("* ");
                        else 
                            System.out.print("  ");
                    System.out.println("\n");
                }
                       
              
           }
       
       
       
        public static void BaiTap34(){
        String hoten ;
        Scanner scan = new Scanner(System.in);
        System.out.print("Ho Ten : ");
        hoten = String.valueOf(scan.nextLine());
        int MSSV;
        System.out.print("MSSV : ");
        MSSV = Integer.parseInt(scan.nextLine());
        double Toan;
        System.out.print("Toan : ");
        Toan = Integer.parseInt(scan.nextLine());
        double Ly;
        System.out.print("Ly : ");
        Ly = Integer.parseInt(scan.nextLine());
        double Hoa;
        System.out.print("Hoa : ");
        Hoa = Integer.parseInt(scan.nextLine());
        double DTB = (Toan + Hoa + Ly) / 3;
        if(DTB >= 8 && DTB <= 10)
        {
            System.out.println("Hoc sinh vua nhap co diem trung binh la :" + DTB + "Xep loai : Gioi");
        }
        else if (DTB >= 7 && DTB < 8)
        {
            System.out.println("Hoc sinh vua nhap co diem trung binh la :" + DTB + "Xep loai : Kha");
        }
        else if(DTB >= 5 && DTB < 7)
        {
            System.out.println("Hoc sinh vua nhap co diem trung binh la :" + DTB + "Xep loai : Trung Binh");
        }
        else  if(DTB >= 3.5 && DTB < 5)
        {
            System.out.println("Hoc sinh vua nhap co diem trung binh la :" + DTB + "Xep loai : Yeu");
        }
        else {
            System.out.println("Hoc sinh vua nhap co diem trung binh la :" + DTB + "Xep loai : Kem");
        }
        
     }
        
         public static void BaiTap35(){
        String hoten ;
        Scanner scan = new Scanner(System.in);
        System.out.print("Ho Ten : ");
        hoten = String.valueOf(scan.nextLine());
        GregorianCalendar g = new GregorianCalendar();
        System.out.println("Nhap nam sinh");
        int ngaysinh = Integer.parseInt(scan.nextLine());
        System.out.println("So tuoi cua ban la : " + (g.get(GregorianCalendar.YEAR) - ngaysinh));  
        
    }
           public static void BaiTap36(){
               float a;
               Scanner scan = new Scanner(System.in);
               System.out.print(" so thuc thu nhat:");
               String str1 = scan.nextLine();
               a =  Float.valueOf(str1);
               float b;
               System.out.print(" so thuc thu hai:");
               String str2 = scan.nextLine();
               b =  Float.valueOf(str2);
             
               while(true){
                   LuaChon();
                int key = Integer.parseInt(scan.nextLine());
               switch(key){
                   case 1 :
                       System.out.println("Ket qua cua phep toan tren la :" +( a + b));
                       break;
                   case 2:
                       System.out.println("Ket qua cua phep toan tren la :" +( a - b));
                       break;
                   case 3:
                       System.out.println("Ket qua cua phep toan tren la :" +( a * b));
                       break;
                   case 4:
                       System.out.println("Ket qua cua phep toan tren la :" +( a / b));
                       break;
                   case 5:
                       System.out.println("Ket qua cua phep toan tren la :" +( a % b));
                       break;
                   default:
                    System.out.println("Vui long chon 1-7");
                    break;
               }
            }
        }
        
      
             
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan = new  Scanner(System.in);
        while(true){
            ThucDon();
            int key = Integer.parseInt(scan.nextLine());
            switch(key){
                case 1 :
                    BaiTap01();
                    break;
                case 2 :
                    BaiTap02();
                    break;
                case 3 :
                    BaiTap03();
                    break;
                case 4 :
                    BaiTap04();
                    break;
                case 5 :
                    BaiTap05();
                    break;
                case 6 :
                    BaiTap06();
                    break;
                case 7 :
                    BaiTap07();
                    break;
                case 8 :
                    BaiTap08();
                    break;
                case 9 :
                    BaiTap09();
                    break;
                case 10 :
                    BaiTap10();
                    break;
                case 11 :
                    BaiTap11();
                    break;
                case 12 :
                    BaiTap12();
                    break;
                case 13 :
                    BaiTap13();
                    break;
                case 14 :
                    BaiTap14();
                    break;
                case 15 :
                    BaiTap15();
                    break;
                case 16 :
                    BaiTap16();
                    break;
                case 17 :
                    BaiTap17();
                    break;
                case 18 :
                    BaiTap18();
                    break;
                case 19 :
                    BaiTap19();
                    break;
                case 20 :
                    BaiTap20();
                    break;
                case 21 :
                    BaiTap21();
                    break;
                case 22 :
                    BaiTap22();
                    break;
                case 23 :
                    BaiTap23();
                    break;
                case 24 :
                    BaiTap24();
                    break;
                case 25 :
                    BaiTap25();
                    break;
                case 26 :
                    BaiTap26();
                    break;
                case 27:
                    BaiTap27();
                    break;
                case 28:
                    BaiTap28();
                    break;
                case 29:
                    BaiTap29();
                    break;
                case 30:
                    BaiTap30();
                    break;
                case 31:
                    BaiTap31();
                    break;
                case 32:
                    BaiTap32();
                    break;
                case 33:
                    BaiTap33();
                    break;
                case 34:
                    BaiTap34();
                    break;
                case 35:
                    BaiTap35();
                    break;
                case 36:
                    BaiTap36();
                    break;
                case 37 :
                    System.exit(1);
                    break;
                default:
                    System.out.println("Vui long chon 1-37");
                    break;
            }
        }
    }
}
